<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - Telchina.AI</title>
    <link rel="icon" type="image/svg+xml" href="/vanna.svg" />
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .login-container {
            background: white;
            padding: 2rem;
            border-radius: 10px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
        }
        
        .logo {
            text-align: center;
            margin-bottom: 2rem;
        }
        
        .logo img {
            width: 60px;
            height: 60px;
            margin-bottom: 1rem;
        }
        
        .logo h1 {
            color: #333;
            font-size: 1.5rem;
            font-weight: 600;
        }
        
        .form-group {
            margin-bottom: 1.5rem;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            color: #555;
            font-weight: 500;
        }
        
        .form-group input {
            width: 100%;
            padding: 0.75rem;
            border: 2px solid #e1e5e9;
            border-radius: 5px;
            font-size: 1rem;
            transition: border-color 0.3s;
        }
        
        .form-group input:focus {
            outline: none;
            border-color: #667eea;
        }
        
        .login-btn {
            width: 100%;
            padding: 0.75rem;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s;
        }
        
        .login-btn:hover {
            transform: translateY(-2px);
        }
        
        .login-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }
        
        .error-message {
            color: #e74c3c;
            text-align: center;
            margin-top: 1rem;
            padding: 0.5rem;
            background: #fdf2f2;
            border-radius: 5px;
            display: none;
        }
        
        .remember-me {
            display: flex;
            align-items: center;
            margin-bottom: 1.5rem;
        }
        
        .remember-me input {
            margin-right: 0.5rem;
        }
        
        .remember-me label {
            color: #666;
            font-size: 0.9rem;
            margin-bottom: 0;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="logo">
            <img src="./telchina.svg" alt="Telchina.AI">
            <h1>Telchina.AI</h1>
        </div>
        
        <form id="loginForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" required>
            </div>
            
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required>
            </div>
            
            <div class="remember-me">
                <input type="checkbox" id="rememberMe" name="rememberMe">
                <label for="rememberMe">记住我</label>
            </div>
            
            <button type="submit" class="login-btn" id="loginBtn">登录</button>
            
            <div class="error-message" id="errorMessage"></div>
        </form>
    </div>
    
    <script>
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const rememberMe = document.getElementById('rememberMe').checked;
            const loginBtn = document.getElementById('loginBtn');
            const errorMessage = document.getElementById('errorMessage');
            
            // 简单的用户名密码验证（实际项目中应该从服务器验证）
            if (username === 'admin' && password === 'admin123') {
                loginBtn.disabled = true;
                loginBtn.textContent = '登录中...';
                
                // 设置登录状态和API令牌
                const loginData = {
                    isLoggedIn: true,
                    username: username,
                    loginTime: new Date().getTime(),
                    apiToken: 'your-secret-token'  // 添加API令牌
                };
                
                if (rememberMe) {
                    localStorage.setItem('telchinaAuth', JSON.stringify(loginData));
                } else {
                    sessionStorage.setItem('telchinaAuth', JSON.stringify(loginData));
                }
                
                // 模拟登录延迟
                setTimeout(() => {
                    // 获取重定向URL或默认跳转到首页
                    const urlParams = new URLSearchParams(window.location.search);
                    let redirectUrl = urlParams.get('redirect') || '/index.html';
                    
                    // 添加认证标记到URL中
                    const authToken = 'logged_' + new Date().getTime();
                    if (redirectUrl.includes('?')) {
                        redirectUrl += '&auth=' + authToken;
                    } else {
                        redirectUrl += '?auth=' + authToken;
                    }
                    
                    window.location.href = redirectUrl;
                }, 1000);
            } else {
                errorMessage.textContent = '用户名或密码错误';
                errorMessage.style.display = 'block';
                
                // 3秒后隐藏错误消息
                setTimeout(() => {
                    errorMessage.style.display = 'none';
                }, 3000);
            }
        });
        
        // 检查是否已经登录
        function checkLoginStatus() {
            const authData = localStorage.getItem('telchinaAuth') || sessionStorage.getItem('telchinaAuth');
            if (authData) {
                try {
                    const loginData = JSON.parse(authData);
                    if (loginData.isLoggedIn) {
                        // 已登录，重定向到目标页面
                        const urlParams = new URLSearchParams(window.location.search);
                        let redirectUrl = urlParams.get('redirect') || '/index.html';
                        
                        // 添加认证标记到URL中
                        const authToken = 'logged_' + new Date().getTime();
                        if (redirectUrl.includes('?')) {
                            redirectUrl += '&auth=' + authToken;
                        } else {
                            redirectUrl += '?auth=' + authToken;
                        }
                        
                        window.location.href = redirectUrl;
                    }
                } catch (e) {
                    // 清除无效的登录数据
                    localStorage.removeItem('telchinaAuth');
                    sessionStorage.removeItem('telchinaAuth');
                }
            }
        }
        
        // 页面加载时检查登录状态
        checkLoginStatus();
    </script>
</body>
</html>